﻿<%@ WebHandler Language="C#" Class="info" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Chenxin.Lib.House;

public class info : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Buffer = true;
        context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        //返回查询结果集
        DataSet ds = new DataSet();
        //页显示行数
        int PageSize = 3;
        //排序
        string OrderField="";
        //条件 
        string StrWhere = "";
        //欲选择字段列表 
        string FieldList = "";
        //子查询欲选择字段列表  
        string TableFieldList = "";
        //返回结果HTML
        string output = "";
        //得到查询ID
        string recordid = "";
        if (!string.IsNullOrEmpty(context.Request.QueryString["recordid"]))
        {
            recordid = context.Request.QueryString["recordid"];
        }        
        //页码
        int pageindex = 1;
        if (!string.IsNullOrEmpty(context.Request.QueryString["pageIndex"]))
        {
            pageindex = int.Parse(context.Request.QueryString["pageIndex"]);
        }
        //类型
        string type = "";
        if (!string.IsNullOrEmpty(context.Request.QueryString["type"]))
        {
            type = context.Request.QueryString["type"];
        }
        
        //返回房源管理页 插入层的方法及HTML
        if (type == "house")
        {
            OrderField = "TraceTime desc";
            StrWhere = "HouseId='" + recordid + "'";
            FieldList = "Tractor,TraceTime,TraceContext";
            TableFieldList = "Tractor,CONVERT(varchar(12) , TraceTime, 111 ),TraceContext";
            //根据sql执行查询
            ds = Chenxin.Lib.House.DAL.House_BaseInfo.GetList(pageindex, PageSize, OrderField, "House_TraceInfo", StrWhere, FieldList, TableFieldList, false);
            output = HouseManagerHTML(ds.Tables[0].Rows[0][0].ToString(), new Guid(recordid));
        }
        
        //返回楼盘查询页 插入层的方法及HTML
        else if (type == "comm")
        {
            PageSize = 4;
            OrderField = "AddTime desc";
            StrWhere = "CommunityId='" + recordid + "'";
            FieldList = "BuildingName,Floor,UnitNum,AddPerson,AddTime";
            TableFieldList = "BuildingName,Floor,UnitNum,AddPerson,CONVERT(varchar(12) , AddTime, 111 ) as AddTime";
            //根据sql执行查询
            ds = Chenxin.Lib.House.DAL.Community_BaseInfo.GetList(pageindex, PageSize, OrderField, "Community_BuildingInfo", StrWhere, FieldList, TableFieldList, false);
            output = CommunityManagerHTML(ds.Tables[0].Rows[0][0].ToString());
        }

        else if (type == "allot")
        {
            PageSize = 10;
            OrderField = "Adddate desc";
            StrWhere = "OprPersonId='" + recordid + "'";
            FieldList = "HouseId,Adddate,HouseCode,Community,OprPerson,OprDepart";
            TableFieldList = "HouseId,CONVERT(varchar(12) , Adddate, 111 ) as Adddate,HouseCode,isnull(Community,'')+isnull(BuildingName,'')+isnull(Room,'') as Community,OprPerson,OprDepart";
            ds = Chenxin.Lib.House.DAL.House_BaseInfo.GetList(pageindex, PageSize, OrderField, "House_BaseInfo", StrWhere, FieldList, TableFieldList, false);
            output = AllotHTML(ds.Tables[0].Rows[0][0].ToString());
        }

        else if (type == "allot_custom")
        {
            PageSize = 10;
            OrderField = "Adddate desc";
            StrWhere = "OprPersonId='" + recordid + "'";
            FieldList = "CustomerId,Adddate,CustomerCode,CustomerName,OprPerson,OprDepart";
            TableFieldList = "CustomerId,CONVERT(varchar(12) , Adddate, 111 ) as Adddate,CustomerCode,CustomerName,OprPerson,OprDepart";
            ds = Chenxin.Lib.House.DAL.House_BaseInfo.GetList(pageindex, PageSize, OrderField, "Customer_BaseInfo", StrWhere, FieldList, TableFieldList, false);
            output = AllotHTML(ds.Tables[0].Rows[0][0].ToString());
        }

        context.Response.ContentType = "text/plain";
        context.Response.Buffer = true;
        context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        context.Response.Write(output);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    
    //输出房源管理插入层的HTML
    private string HouseManagerHTML(string count,Guid recordid)
    {
        Chenxin.Lib.House.Entity.House_BaseInfo house_BaseInfo = Chenxin.Lib.House.DAL.House_BaseInfo.GetModel(recordid);
        string  strProtect = "";
        if (house_BaseInfo.IsProtectHouse) {
            strProtect = "<li class='widli60'><a href='#' id='hrefUnProtect' onclick= 'initUnProtect();' class='bluelink'>取消保护</a></li>";
        } else {
            strProtect = "<li class='widli60'><a href='#' id='hrefProtect'  onclick= 'initProtect();' class='bluelink'>保护</a></li>";
        }
        
        string request = "";
        if (house_BaseInfo.IsNeedTran)
        {
            request = "<li class='widli75'><a href='#'  onclick= 'initConfirmRequestChange();' class='bluelink'>变更确认</a></li>";
        }
        else {
            request = "<li class='widli75'><a href='#'  onclick= 'initRequestChange();' class='bluelink'>请求变更</a></li>";
        }
        
        string locked = "";
        if (house_BaseInfo.Status != 30)
        {
            locked = "<li class='widli60'><a href='#' onclick= 'initLocked();' class='bluelink'>封盘</a></li>";
        }
        else
        {
            locked = "<li class='widli60'><a href='#'  onclick= 'initUnLocked();' class='bluelink'>封盘</a></li>";
        }
        
        
        string html ="<div class='gendan_box'>"
        + "        <div class='c_box'>"
        + "        <div class='c_name'>业主姓名：" + house_BaseInfo.CustomerName + "</div><div class='gend_icon'><a href='#'  onclick= 'initTraceAdd();' class='bluelink'>我要跟单</a></div><div class='tel_icon'><a href='#' class='bluelink'>查看电话</a></div>"
        + "        </div>"
        + "        <div class='g_box'>"
        + "        <div class='g_tab'>"

        + "        <table width='100%' border='0' cellspacing='0' cellpadding='0' class='tablesorter' id='linkTable'>"
        + "  <tr>"
        + "    <td width='20%'><span  class='fc_blue'><b>跟单人</b></span></td>"
        + "    <td width='18%'><span  class='fc_blue'><b>跟单时间</b></span></td>"
        + "    <td width='62%'><span  class='fc_blue'><b>跟单内容</b></span></td>"
        + "  </tr></table>"
        + "<div id=\"pagination\" class=\"pagination\"></div>"
        + "        </div>       "
        + "        <div class='g_menu'>"
        + "        <ul>"

        + "       <li class='widli60'><a href='ShowDetailInfo.aspx?houseid=" + house_BaseInfo.HouseId + "' target='_blank' class='bluelink'>详情</a></li>" + locked + "<li class='widli75'><a href='#' class='bluelink'>业绩申请</a></li><li class='widli60'>"
        +           "<a href='#' class='bluelink favors'>收藏</a></li>"+strProtect + request
        + "       <li class='widli60'><a href='#' id='hrefMarked' onclick= 'initMarked();' class='bluelink'>备案</a></li><li class='widli60'><a href='#' class='bluelink compareHouse'>对比</a></li><li class='widli75'><a href='#' class='bluelink'>分配任务</a></li>"
        + "       <li class='widli60'><a href='#' class='bluelink'>带看</a></li> <li class='widli60'><a href='#' onclick= 'initKeyAdd();' class='bluelink'>钥匙</a></li> <li class='widli75'><a href='#' class='bluelink'>意向金</a></li>"
        + "        <li class='widli60'><a href='#' class='bluelink'>报备</a></li><li class='widli60'><a href='#' onclick= 'initAddenTrust();' class='bluelink'>委托</a></li><li class='widli75'><a href='#' class='bluelink'>贷款预审</a></li>"
        + "        </ul>"
        + "        </div>"
        + "        </div>"
        + "        </div>";

        //添加跟单总数
        html += "<input type='hidden' id='tdiv_count' value='" + count + "' />";

        return html;
    }
    
    //输出楼盘管理插入层的HTML
    private string CommunityManagerHTML(string count)
    {
        string html = "<div class='gendan_box'>"
        + "        <div class='g_box'>"
        + "        <div class='g_tab'>"

        + "        <table width='100%' border='0' cellspacing='0' cellpadding='0' class='tablesorter' id='linkTable'>"
        + "  <tr>"
        + "    <td width='30%'><span  class='fc_blue'><b>楼栋名称</b></span></td>"
        + "    <td width='15%'><span  class='fc_blue'><b>层数</b></span></td>"
        + "    <td width='15%'><span  class='fc_blue'><b>创建人</b></span></td>"
        + "    <td width='20%'><span  class='fc_blue'><b>创建时间</b></span></td>"
        + "    <td width='20%'><span  class='fc_blue'><b>操作</b></span></td>"
        + "  </tr></table>"
        + "<div id=\"pagination\" class=\"pagination\"></div>"
        + "        </div>       "
        + "        <div class='g_menu'>"
        + "        <div class='wind120'><input type='button' id='btn_add_building' value='  添加栋号' class='btn_add'/></div>"
        + "        <div class='wind120'><input type='button' id='btn_bulkadd_building' value='  批量添加' class='btn_add'/></div>"
        + "        </div>"
        + "        </div>"
        + "        </div>";

        //添加跟单总数
        html += "<input type='hidden' id='tdiv_count' value='" + count + "' />";
        return html;
    }
    
    //输出房源分配总数
    private string AllotHTML(string count)
    {
        string html = "<input type='hidden' id='tdiv_count' value='" + count + "' />";
        return html;
    }
}